package cn.leestudio.springboot.dao.leestudio;

import cn.leestudio.springboot.model.User;
import cn.leestudio.springboot.model.UserExample;
import java.util.List;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.InsertProvider;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectProvider;
import org.apache.ibatis.annotations.Update;
import org.apache.ibatis.annotations.UpdateProvider;
import org.apache.ibatis.type.JdbcType;

public interface UserMapper {
    @Delete({
        "delete from users",
        "where id = #{id,jdbcType=INTEGER}"
    })
    int deleteByPrimaryKey(Integer id);

    @Insert({
        "insert into users (id, firstName, ",
        "lastName, sex, createdAt, ",
        "updatedAt)",
        "values (#{id,jdbcType=INTEGER}, #{firstname,jdbcType=VARCHAR}, ",
        "#{lastname,jdbcType=VARCHAR}, #{sex,jdbcType=INTEGER}, #{createdat,jdbcType=TIMESTAMP}, ",
        "#{updatedat,jdbcType=TIMESTAMP})"
    })
    int insert(User record);

    @InsertProvider(type=UserSqlProvider.class, method="insertSelective")
    int insertSelective(User record);

    @SelectProvider(type=UserSqlProvider.class, method="selectByExample")
    @Results({
        @Result(column="id", property="id", jdbcType=JdbcType.INTEGER, id=true),
        @Result(column="firstName", property="firstname", jdbcType=JdbcType.VARCHAR),
        @Result(column="lastName", property="lastname", jdbcType=JdbcType.VARCHAR),
        @Result(column="sex", property="sex", jdbcType=JdbcType.INTEGER),
        @Result(column="createdAt", property="createdat", jdbcType=JdbcType.TIMESTAMP),
        @Result(column="updatedAt", property="updatedat", jdbcType=JdbcType.TIMESTAMP)
    })
    List<User> selectByExample(UserExample example);

    @Select({
        "select",
        "id, firstName, lastName, sex, createdAt, updatedAt",
        "from users",
        "where id = #{id,jdbcType=INTEGER}"
    })
    @Results({
        @Result(column="id", property="id", jdbcType=JdbcType.INTEGER, id=true),
        @Result(column="firstName", property="firstname", jdbcType=JdbcType.VARCHAR),
        @Result(column="lastName", property="lastname", jdbcType=JdbcType.VARCHAR),
        @Result(column="sex", property="sex", jdbcType=JdbcType.INTEGER),
        @Result(column="createdAt", property="createdat", jdbcType=JdbcType.TIMESTAMP),
        @Result(column="updatedAt", property="updatedat", jdbcType=JdbcType.TIMESTAMP)
    })
    User selectByPrimaryKey(Integer id);

    @UpdateProvider(type=UserSqlProvider.class, method="updateByPrimaryKeySelective")
    int updateByPrimaryKeySelective(User record);

    @Update({
        "update users",
        "set firstName = #{firstname,jdbcType=VARCHAR},",
          "lastName = #{lastname,jdbcType=VARCHAR},",
          "sex = #{sex,jdbcType=INTEGER},",
          "createdAt = #{createdat,jdbcType=TIMESTAMP},",
          "updatedAt = #{updatedat,jdbcType=TIMESTAMP}",
        "where id = #{id,jdbcType=INTEGER}"
    })
    int updateByPrimaryKey(User record);
}